//
//  HXItemCorpMessageTableViewCell.m
//  KD
//
//  Created by ifly on 16/3/25.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXItemCorpMessageTableViewCell.h"

#import "HXCropMessageBackgroundView.h"

@interface HXItemCorpMessageTableViewCell()
@property (weak, nonatomic) IBOutlet UILabel *typeNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *corpNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *personLabel;
@property (weak, nonatomic) IBOutlet UIButton *projectMemberBtn;

@property (nonatomic,strong) NSMutableArray <HXGetProjectMemberDetailModel *>* dataArr;

@end

@implementation HXItemCorpMessageTableViewCell

/**
 请求数据
 */
-(void)getDate{
    
    _dataArr = [NSMutableArray array];
    
    [SVProgressHUD showWithStatus:@"正在加载"];
    [NetworkAPI getProjectMemberWithCorpType:_data.CorpType
                                      PrjNum:_sendModelStr
                                     KeyGuid:@""
                                    CorpCode:_data.CorpCode
                                     Success:^(HXGetProjectMemberModel *result) {
                                         if ([result.code isEqualToString:@"200"]) {
                                             
                                             
                                             [self.dataArr addObjectsFromArray:result.result];
                                             [SVProgressHUD showSuccessWithStatus:@"加载成功"];
                                             
                                             
                                             HXCropMessageBackgroundView * bgView = [[HXCropMessageBackgroundView alloc]
                                                                                     initWithFrame:CGRectMake(0, 0, HXSCREEN_WIDTH, HXSCREEN_HEIGHT)];
                                             bgView.type = ProjectHistoryType;
                                             
//                                             HXCropMessageBackgroundView * bgView = [[HXCropMessageBackgroundView alloc]
//                                                                                     initWithFrame:CGRectMake(0, 0, HXSCREEN_WIDTH, HXSCREEN_HEIGHT)
//                                                                                     withCorpType:_data.CorpType
//                                                                                     withPrjNum:_sendModelStr
//                                                                                     withKeyGuid:@""];
                                             
                                             bgView.dataArray = self.dataArr;
                                             
                                             [bgView showView];
                                             
                                         }
                                         else if ([result.code isEqualToString:@"400"]) {
                                             
                                             [SVProgressHUD showErrorWithStatus:@"请求失败,请重新尝试"];
                                             
                                         }else {
                                             
                                             [SVProgressHUD showErrorWithStatus:@"暂无数据"];
                                             
                                         }
                                     } failure:^(NSError *err) {
                                         [SVProgressHUD showErrorWithStatus:@"网络请求错误"];
                                         
                                     }];
    
}



- (IBAction)projectMemberBtn:(UIButton *)sender {
    if (sender.tag == 1001) {
        
        [self getDate];
        
        
    }else if (sender.tag == 1002){
    
        [self getDate];

        
//        HXCropMessageBackgroundView * bgView = [[HXCropMessageBackgroundView alloc]
//                                                initWithFrame:CGRectMake(0, self.superview.height-HXSCREEN_HEIGHT, HXSCREEN_WIDTH, HXSCREEN_HEIGHT)
//                                                withCorpType:_data.CorpType
//                                                withPrjNum:_sendModelStr
//                                                withKeyGuid:@""];
//        
//        
//        [bgView showView];
    }
    
}

-(void)setSendModelStr:(NSString *)sendModelStr {
    
    _sendModelStr = sendModelStr;
}


- (void)setData:(HXMessageDetailsListArrayModel *)data{
    _data = data;

    if([GlobalUtil isNilValue:_data.CorpTypeName]){
        self.typeNameLabel.text = @"暂无";
    }else{
        self.typeNameLabel.text = _data.CorpTypeName;

        if ([_data.CorpTypeName isEqualToString:@"施工单位"]) {
            _projectMemberBtn.enabled = YES;
            _projectMemberBtn.hidden = NO;
            _projectMemberBtn.tag = 1001;
        }
        else if ([_data.CorpTypeName isEqualToString:@"监理单位"]) {
            _projectMemberBtn.enabled = YES;
            _projectMemberBtn.hidden = NO;
            _projectMemberBtn.tag = 1002;
        }
        else {
            _projectMemberBtn.enabled = NO;
            _projectMemberBtn.hidden = YES;
        }
    }
    
    if([GlobalUtil isNilValue:_data.CorpName]){
        self.corpNameLabel.text = @"暂无";
    }else{
        self.corpNameLabel.text = _data.CorpName;
    }
    
    if([GlobalUtil isNilValue:_data.CorpFZRTel]){
        self.phoneLabel.text = @"暂无";
    }else{
        self.phoneLabel.text = _data.CorpFZRTel;
    }

    if([GlobalUtil isNilValue:_data.CorpFZR]){
        self.personLabel.text = @"暂无";
    }else{
        self.personLabel.text = _data.CorpFZR;
    }

}

- (void)setFrame:(CGRect)frame
{
//    frame.origin.y = 5;
//    frame.size.height = frame.size.height - 10;
//    
    [super setFrame:frame];
}
@end
